import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.*;
import java.lang.Math;

public class Circle extends MobileSprite {
        private CircleGraphic image;
        public Circle(String n, int r, Color c)
        {
                image = new CircleGraphic(n,r,c);
        }
        
        /**
         * Moves the circle to a random neighbor
        */ 
        public boolean move(HexGrid world)
        {
    		moveCount = 0;
    		int [] lastLocation = getLocation();

    		Collection<Hex> neighbors = world.get_neighbors(lastLocation);
    		
    		if(neighbors.size()==0 || moved)
    			return false;
    		boolean failed = true;
    		while(failed){
    		double rand1 = Math.random()*neighbors.size();
    		int rand = (int)(rand1);
    		for(Hex i:neighbors){
    			if(rand-- == 0){
    				if(i.moveIntoHex(this)){		
    					world.get_hex(lastLocation).leaveHex();
    					failed = false;
    					break;
    				}
    			}
    		}
    		}
    		moved = true;
    		oldLocation = lastLocation;
    		setParameters(world);
		return moved;
        }



	@Override
	public void drawSprite(Graphics g, int x, int y) {
		x -= (double)(xDistance)*(1-(double)(moveCount)/24);
		y -= (double)(yDistance)*(1-(double)(moveCount)/24);
		this.image.draw(g,x,y);
		moveCount++;
	}

}
